import { ApiProperty } from "@nestjs/swagger";

class BaseResponseVO {
    /**
     * 状态码
     */
    @ApiProperty({ example: 200, description: "状态码" })
    code: number;

    /**
     * 消息
     */
    @ApiProperty({ example: "成功", description: "消息" })
    msg: string;

    constructor(code: number, msg: string) {
        this.code = code;
        this.msg = msg;
    }
}

export class BaseSuccessResponseVO<T = any> extends BaseResponseVO {
    /**
     * 响应数据
     */
    @ApiProperty({ description: "响应数据" })
    data: T;

    constructor(code: number, msg: string, data?: T) {
        super(code, msg);
        this.data = data;
    }
}

export class BaseFailureResponseVO<T = any> extends BaseResponseVO {
    /**
     * 错误信息
     */
    @ApiProperty({ description: "错误信息", required: false })
    error: any;

    /**
     * 请求路径
     */
    @ApiProperty({ example: "/api/users", description: "请求路径" })
    path: string;

    /**
     * 时间戳
     */
    @ApiProperty({ example: "2023-09-27 10:20:30", description: "时间戳" })
    timestamp: string;

    constructor(code: number, msg: string, path?: string, error?: any, timestamp?: string) {
        super(code, msg);
        this.path = path;
        this.error = error;
        this.timestamp = timestamp;
    }
}
